﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
         
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var user = TextBox1.Text.Trim();
            var pwd = TextBox2.Text.Trim();
            var sql = string.Format("select * from Users where UserName='{0}'", user);
            var dt= DbHelper.GetData(sql);
            if (dt.Rows.Count ==1)
            {
                var row = dt.Rows[0];
                var password = row.ItemArray[2].ToString();
                var isInvoke =(bool) row.ItemArray[3];
                var isDelete = (bool)row.ItemArray[4];

                if (isDelete)
                {
                    Response.Write("用户已被删除");
                }
                else
                {
                    if (isInvoke)
                    {
                         if (password==pwd)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Response.Write("密码错误");
                        }
                    }
                    else
                    {
                        Response.Write("用户已被禁用");
                    }
                }

            }
            else
            {
                Response.Write("用户名不存在");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("register.aspx");
        }
    }
}
